package com.alpha.utils.msg;

import java.io.Serializable;

public class ResponseMsg<T> implements Serializable {
    private static final long serialVersionUID = 1234560319171014184L;
    private String retCode = String.valueOf(200);
    private String errorDesc = "";
    private String message = "";
    private T responseBody;
    private final long timestamp = System.currentTimeMillis();

    public ResponseMsg() {
    }

    public static <T> ResponseMsg<T> OK() {
        ResponseMsg<T> r = new ResponseMsg();
        r.setRetCode(String.valueOf(200));
        return r;
    }

    public static <T> ResponseMsg<T> OK(T data) {
        ResponseMsg<T> r = new ResponseMsg();
        r.setRetCode(String.valueOf(200));
        r.setResponseBody(data);
        return r;
    }

    public static <T> ResponseMsg<T> OK(String msg, T data) {
        ResponseMsg<T> r = new ResponseMsg();
        r.setRetCode(String.valueOf(200));
        r.setMessage(msg);
        r.setResponseBody(data);
        return r;
    }

    public static <T> ResponseMsg<T> error(String msg) {
        return error(500, msg);
    }

    public static <T> ResponseMsg<T> error(int code, String msg) {
        return error(code, msg, null);
    }

    public static <T> ResponseMsg<T> error(String msg, T data) {
        return error(500, msg, data);
    }

    public static <T> ResponseMsg<T> error(int code, String msg, T data) {
        ResponseMsg<T> r = new ResponseMsg();
        r.setRetCode(String.valueOf(code));
        r.setMessage(msg);
        r.setResponseBody(data);
        return r;
    }

    public String getRetCode() {
        return this.retCode;
    }

    public ResponseMsg<T> setRetCode(String retCode) {
        this.retCode = retCode;
        return this;
    }

    public String getErrorDesc() {
        return this.errorDesc;
    }

    public ResponseMsg<T> setErrorDesc(String errorDesc) {
        this.errorDesc = errorDesc;
        return this;
    }

    public String getMessage() {
        return this.message;
    }

    public ResponseMsg<T> setMessage(String message) {
        this.message = message;
        return this;
    }

    public T getResponseBody() {
        return this.responseBody;
    }

    public ResponseMsg<T> setResponseBody(T responseBody) {
        this.responseBody = responseBody;
        return this;
    }

    public long getTimestamp() {
        return this.timestamp;
    }

    public String toString() {
        return "ResponseMsg{retCode='" + this.retCode + '\'' + ", errorDesc='" + this.errorDesc + '\'' + ", message='" + this.message + '\'' + ", responseBody=" + this.responseBody + ", timestamp=" + this.timestamp + '}';
    }
}
